#include <QDebug>
#include "Qsci/qsciscintilla.h"
#include "Jinja2Lexer.h"
#include "Include/Settings.h"

namespace Lexers {

Jinja2Lexer::Jinja2Lexer(QObject *parent):
    QsciLexerHTML(parent)
{
}

Jinja2Lexer::~Jinja2Lexer()
{

}

QsciLexer * Jinja2Lexer::lexer()
{
    return this;
}

QList<int> Jinja2Lexer::styles()
{
    QList<int> styles;
    styles << Default << Tag << UnknownTag << Attribute << UnknownAttribute << HTMLNumber << HTMLDoubleQuotedString <<
              HTMLSingleQuotedString << OtherInTag << HTMLComment << Entity << XMLTagEnd << XMLStart << XMLEnd << Script << CDATA <<
              HTMLValue << JavaScriptStart << JavaScriptDefault << JavaScriptComment << JavaScriptCommentLine << JavaScriptCommentDoc <<
              JavaScriptNumber << JavaScriptWord << JavaScriptKeyword << JavaScriptDoubleQuotedString << JavaScriptSingleQuotedString <<
              JavaScriptSymbol << JavaScriptUnclosedString << JavaScriptRegex << ASPPythonStart << ASPPythonDefault <<  ASPPythonComment <<
              ASPPythonNumber << ASPPythonDoubleQuotedString << ASPPythonSingleQuotedString << ASPPythonKeyword << ASPPythonTripleSingleQuotedString <<
              ASPPythonTripleDoubleQuotedString << ASPPythonClassName << ASPPythonFunctionMethodName << ASPPythonOperator << ASPPythonIdentifier <<
              ASPAtStart;
    return styles;
}

QString Jinja2Lexer::description(int style) const
{
    switch(style){
    case Default: return tr("Default");
    case Tag: return tr("Tag");
    case UnknownTag: return tr("Unknown tag");
    case Attribute: return tr("Attribute");
    case UnknownAttribute: return tr("Unknown attribute");
    case HTMLNumber: return tr("HTML number");
    case HTMLDoubleQuotedString: return tr("HTML double quoted string");
    case HTMLSingleQuotedString: return tr("HTML single quoted string");
    case OtherInTag: return tr("Other in tag");
    case HTMLComment: return tr("HTML comment");
    case Entity: return tr("Entity");
    case XMLTagEnd: return tr("XML tag end");
    case XMLStart: return tr("XML start");
    case XMLEnd: return tr("XML end");
    case Script: return tr("Script");
    case CDATA: return tr("CDATA");
    case HTMLValue: return tr("HTML value");

    case JavaScriptStart: return tr("JavaScript start");
    case JavaScriptDefault: return tr("JavaScript default");
    case JavaScriptComment: return tr("JavaScript comment");
    case JavaScriptCommentLine: return tr("JavaScript comment line");
    case JavaScriptCommentDoc: return tr("JavaScript comment doc");
    case JavaScriptNumber: return tr("JavaScript number");
    case JavaScriptWord: return tr("JavaScript word");
    case JavaScriptKeyword: return tr("JavaScript keyword");
    case JavaScriptDoubleQuotedString: return tr("JavaScript double quoted string");
    case JavaScriptSingleQuotedString: return tr("JavaScript single quoted string");
    case JavaScriptSymbol: return tr("JavaScript symbol");
    case JavaScriptUnclosedString: return tr("JavaScript unclosed string");
    case JavaScriptRegex: return tr("JavaScript regex");

    case ASPAtStart: return tr("Script start");
    case ASPPythonStart: return tr("ASP Python start");
    case ASPPythonDefault: return tr("ASP Python default");
    case ASPPythonComment: return tr("ASP Python comment");
    case ASPPythonNumber: return tr("ASP Python number");
    case ASPPythonDoubleQuotedString: return tr("ASP Python double quoted string");
    case ASPPythonSingleQuotedString: return tr("ASP Python single quoted string");
    case ASPPythonKeyword: return tr("ASP Python keyword");
    case ASPPythonTripleSingleQuotedString: return tr("ASP Python triple single quoted string");
    case ASPPythonTripleDoubleQuotedString: return tr("ASP Python triple double quoted string");
    case ASPPythonClassName: return tr("ASP Python class name");
    case ASPPythonFunctionMethodName: return tr("ASP Python function method name");
    case ASPPythonOperator: return tr("ASP Python operator");
    case ASPPythonIdentifier: return tr("ASP Python identifier");

    }
    return "";
}
QString Jinja2Lexer::nameInTheme(int style) const
{
    switch(style){
    case Default: return "default";
    case Tag: return "tag";
    case UnknownTag: return "unknownTag";
    case Attribute: return "attribute";
    case UnknownAttribute: return "unknownAttribute";
    case HTMLNumber: return "HTMLNumber";
    case HTMLDoubleQuotedString: return "HTMLDoubleQuotedString";
    case HTMLSingleQuotedString: return "HTMLSingleQuotedString";
    case OtherInTag: return "OtherInTag";
    case HTMLComment: return "HTMLComment";
    case Entity: return "Entity";
    case XMLTagEnd: return "XMLTagEnd";
    case XMLStart: return "XMLStart";
    case XMLEnd: return "XMLEnd";
    case Script: return "Script";
    case CDATA: return "CDATA";
    case HTMLValue: return "HTMLValue";

    case JavaScriptStart: return "JavaScriptStart";
    case JavaScriptDefault: return "JavaScriptDefault";
    case JavaScriptComment: return "JavaScriptComment";
    case JavaScriptCommentLine: return "JavaScriptCommentLine";
    case JavaScriptCommentDoc: return "JavaScriptCommentDoc";
    case JavaScriptNumber: return "JavaScriptNumber";
    case JavaScriptWord: return "JavaScriptWord";
    case JavaScriptKeyword: return "JavaScriptKeyword";
    case JavaScriptDoubleQuotedString: return "JavaScriptDoubleQuotedString";
    case JavaScriptSingleQuotedString: return "JavaScriptSingleQuotedString";
    case JavaScriptSymbol: return "JavaScriptSymbol";
    case JavaScriptUnclosedString: return "JavaScriptUnclosedString";
    case JavaScriptRegex: return "JavaScriptRegex";

    case ASPAtStart: return "ASPAtStart";
    case ASPPythonStart: return "ASPPythonStart";
    case ASPPythonDefault: return "ASPPythonDefault";
    case ASPPythonComment: return "ASPPythonComment";
    case ASPPythonNumber: return "ASPPythonNumber";
    case ASPPythonDoubleQuotedString: return "ASPPythonDoubleQuotedString";
    case ASPPythonSingleQuotedString: return "ASPPythonSingleQuotedString";
    case ASPPythonKeyword: return "ASPPythonKeyword";
    case ASPPythonTripleSingleQuotedString: return "ASPPythonTripleSingleQuotedString";
    case ASPPythonTripleDoubleQuotedString: return "ASPPythonTripleDoubleQuotedString";
    case ASPPythonClassName: return "ASPPythonClassName";
    case ASPPythonFunctionMethodName: return "ASPPythonFunctionMethodName";
    case ASPPythonOperator: return "ASPPythonOperator";
    case ASPPythonIdentifier: return "ASPPythonIdentifier";
    }
    return "";
}

QString Jinja2Lexer::name()
{
    return "jinja2 + html";
}

void Jinja2Lexer::setTheme(ITheme *)
{

}

void Jinja2Lexer::styleText(int, int)
{
    qDebug() << "style text";
}

QColor Jinja2Lexer::color(int style)
{
    //qDebug() << style << defaultColor(style).name();
    return defaultColor(style);
}

void Jinja2Lexer::refreshProperties()
{
    QsciLexerHTML::refreshProperties();
    emit propertyChanged("lexer.html.django", "1");
}

QFont Jinja2Lexer::defaultFont(int /*style*/) const
{
    return Plugins::Settings::instance()->font();
}
}

